﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary.Entities;
using BCNPCObject.DB;

namespace BCNPCObject
{
    public class cls_NPC_TRTH_DDO_Controller
    {
         #region   Atributes

        private DataSet CMIS_Header = new CMISOutputParameter();
        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private NPC_TRTH_DDO info;

        #endregion

        #region   Constructor

        public cls_NPC_TRTH_DDO_Controller()
        {
            info = new NPC_TRTH_DDO();
        }
        public cls_NPC_TRTH_DDO_Controller(NPC_TRTH_DDO Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public NPC_TRTH_DDO pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region Method

        public IEnumerable<NPC_TRTH_DDO> select_NPC_TRTH_DDO_All(string strMadviqly)
        {
            try
            {
                CMIS2.ResetDB();
                var q = from p in CMIS2.DB.NPC_TRTH_DDO
                        where p.MA_DVIQLY == strMadviqly
                        orderby p.ID_TRTH
                        select p;

                return q;
            }
            catch
            {
                CMIS2.ResetDB(); return null;
            }
        }

        public IEnumerable<NPC_TRTH_DDO> select_NPC_TRTH_DDO_by_id_truythu(long intID)
        {
            try
            {
                CMIS2.ResetDB();
                var q = from p in CMIS2.DB.NPC_TRTH_DDO
                        where p.ID_TRTH == intID
                        select p;

                return q;
            }
            catch
            {
                CMIS2.ResetDB();
                return null;
            }
        }

        public bool insert_NPC_TRTH_DDO(ref string strErr)
        {
            try
            {
                NPC_TRTH_DDO objNPC_TRTH_DDO = new NPC_TRTH_DDO()
                {
                    ID_TRTH = info.ID_TRTH ,
                    MA_DVIQLY = info.MA_DVIQLY ,
                    MA_DDO = info.MA_DDO ,
                    SO_CTO = info.SO_CTO ,
                    MA_CTO = info.MA_CTO ,
                    MA_LDO = info.MA_LDO ,
                    BCS = info.BCS ,
                    TG_CANCU = info.TG_CANCU ,
                    TG_TRTH = info.TG_TRTH ,
                    SL_CANCU = info.SL_CANCU ,
                    SL_TRTHU = info.SL_TRTHU ,
                    SL_THAO = info.SL_THAO ,
                    NGAYTRTH_TU = info.NGAYTRTH_TU ,
                    GIOTRHU_TU = info.GIOTRHU_TU ,
                    PHUTTRHU_TU = info.PHUTTRHU_TU ,
                    NGAYTRTH_DEN = info.NGAYTRTH_DEN ,
                    GIOTRHU_DEN = info.GIOTRHU_DEN ,
                    PHUTTRHU_DEN = info.PHUTTRHU_DEN ,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_TAO = info.NGAY_TAO,
                    TG_MDIEN_CANCU = info.TG_MDIEN_CANCU,
                    TG_MDIEN_TRTHU = info.TG_MDIEN_TRTHU,
                    CHUOI_GIA = info.CHUOI_GIA,
                    THANH_TIEN = info.THANH_TIEN,
                    THANH_TIEN_TRU_SLTHAO = info.THANH_TIEN_TRU_SLTHAO

                };
                CMIS2.DB.NPC_TRTH_DDO.InsertOnSubmit(objNPC_TRTH_DDO);
                CMIS2.DB.SubmitChanges();
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                CMIS2.ResetDB();
                strErr = ex.Message;
                return false;
            }
        }

        public bool update_NPC_TRTH_DDO(ref string strErr)
        {
            try
            {
                NPC_TRTH_DDO objNPC_TRTH_DDO = CMIS2.DB.NPC_TRTH_DDO.Single(c => c.ID_TRTH == info.ID_TRTH&& c.MA_DVIQLY == info.MA_DVIQLY && c.MA_DDO == info.MA_DDO && c.BCS == info.BCS);

                objNPC_TRTH_DDO.SO_CTO = info.SO_CTO;
                objNPC_TRTH_DDO.MA_CTO = info.MA_CTO;
                objNPC_TRTH_DDO.MA_LDO = info.MA_LDO;
                objNPC_TRTH_DDO.BCS = info.BCS;
                objNPC_TRTH_DDO.TG_CANCU = info.TG_CANCU;
                objNPC_TRTH_DDO.TG_TRTH = info.TG_TRTH;
                objNPC_TRTH_DDO.SL_CANCU = info.SL_CANCU;
                objNPC_TRTH_DDO.SL_TRTHU = info.SL_TRTHU;
                objNPC_TRTH_DDO.SL_THAO = info.SL_THAO;
                objNPC_TRTH_DDO.NGAYTRTH_TU = info.NGAYTRTH_TU;
                objNPC_TRTH_DDO.GIOTRHU_TU = info.GIOTRHU_TU;
                objNPC_TRTH_DDO.PHUTTRHU_TU = info.PHUTTRHU_TU;
                objNPC_TRTH_DDO.NGAYTRTH_DEN = info.NGAYTRTH_DEN;
                objNPC_TRTH_DDO.GIOTRHU_DEN = info.GIOTRHU_DEN;
                objNPC_TRTH_DDO.PHUTTRHU_DEN = info.PHUTTRHU_DEN;
                objNPC_TRTH_DDO.NGUOI_TAO = info.NGUOI_TAO;
                objNPC_TRTH_DDO.NGAY_TAO = info.NGAY_TAO;
                objNPC_TRTH_DDO.TG_MDIEN_CANCU = info.TG_MDIEN_CANCU;
                objNPC_TRTH_DDO.TG_MDIEN_TRTHU = info.TG_MDIEN_TRTHU;
                objNPC_TRTH_DDO.CHUOI_GIA = info.CHUOI_GIA;
                objNPC_TRTH_DDO.THANH_TIEN = info.THANH_TIEN;
                objNPC_TRTH_DDO.THANH_TIEN_TRU_SLTHAO = info.THANH_TIEN_TRU_SLTHAO;

                CMIS2.DB.SubmitChanges();

                return true;
            }
            catch(Exception ex)
            {
                CMIS2.ResetDB();
                strErr = ex.Message;
                return false;
            }
        }

        public bool delete_NPC_TRTH_DDO(ref string strErr)
        {
            try
            {
                var query = from p in CMIS2.DB.NPC_TRTH_DDO where p.ID_TRTH == info.ID_TRTH && p.MA_DVIQLY == info.MA_DVIQLY && p.MA_DDO == info.MA_DDO && p.BCS == info.BCS select p;
                if (query != null && query.Count() > 0)
                {
                    CMIS2.DB.NPC_TRTH_DDO.DeleteAllOnSubmit(query.ToList());
                    CMIS2.DB.SubmitChanges();
                    return true;
                }
                return true;
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                CMIS2.ResetDB(); return false;
            }
        }

        #endregion
    }
}
